﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Supersense.db;
/// <summary>
/// Message 的摘要说明
/// </summary>
/// 
namespace Supersense.content
{

    public class Message
    {

        private Database db = new Database();

        public Message()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        public string get_message_by_type(int page)
        {
            int pagesize = 10;
            string sql = "select top " + pagesize + " * from sup_message WHERE id not IN(select top " + (page - 1) * pagesize + " id from sup_message where 1 ORDER BY posttime DESC,id desc) ORDER BY posttime DESC,id desc;";
            return sql;
        }

        public DataView get_message_by_type(string type, int page)
        {
            int pagesize = 10;
            string sql = "select top " + pagesize + " * from sup_message WHERE id not IN(select top " + (page - 1) * pagesize + " id from sup_message  ORDER BY posttime DESC,id desc) ORDER BY posttime DESC,id desc;";
            DataView dv = this.db.executedv(sql);
            if (dv != null)
            {
                return dv;
            }
            else
            {
                return null;
            }
        }

        public DataView get_message_by_type(string type, int page, int pagesize)
        {
            string sql = "select top " + pagesize + " * from sup_message WHERE id not IN(select top " + (page - 1) * pagesize + " id from sup_message ORDER BY posttime DESC,id desc)  ORDER BY posttime DESC,id desc;";
            DataView dv = this.db.executedv(sql);
            if (dv != null)
            {
                return dv;
            }
            else
            {
                return null;
            }
        }

        public Hashtable pageinfo()
        {
            int pagesize = 2;
            string sql = "SELECT COUNT(*) as count FROM sup_message";
            DataTable dt = this.db.executedt(sql);
            int count = int.Parse(dt.Rows[0]["count"].ToString().Trim());

            Hashtable ht = new Hashtable();
            ht.Add("records", count);
            return ht;
        }
    }
}
